﻿package mortal.game.view.copy.defenseCopy.view
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.mvc.core.*;

    public class DefenseShopCellRenderer extends GCellRenderer
    {
        private var _item:BaseItem;
        private var _bg:ScaleBitmap;
        private var _txtName:GTextFiled;
        private var _txtNeedMoney:GTextFiled;

        public function DefenseShopCellRenderer()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.bg(2, 2, 140, 48, this, ImagesConst.InputDisablBg);
            this._item = UIFactory.getUICompoment(BaseItem, 6, 5, this);
            this._item.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            this._item.isDragAble = false;
            this._item.mouseChildren = false;
            this._item.doubleClickEnabled = true;
            this.configEventListener(MouseEvent.ROLL_OVER, this.showCursor);
            this.configEventListener(MouseEvent.ROLL_OUT, this.hidCursor);
            this.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this._txtName = UIFactory.gTextField("" + Language.getString(70859), 50, 5, 92, 20, this);
            this._txtNeedMoney = UIFactory.gTextField("0", 50, 25, 80, 20, this);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bg.dispose(param1);
            this._item.dispose(param1);
            this._txtName.dispose(param1);
            this._txtNeedMoney.dispose(param1);
            this._bg = null;
            this._item = null;
            this._txtName = null;
            this._txtNeedMoney = null;
            return;
        }// end function

        override public function get data() : Object
        {
            return super.data;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_3:int = 0;
            var _loc_4:Array = null;
            var _loc_5:SDefenseCopyBuyItem = null;
            var _loc_6:int = 0;
            super.data = param1;
            var _loc_2:* = param1 as TDefenseCopyShopSell;
            if (_loc_2)
            {
                this._item.itemData = new ItemData(_loc_2.itemCode);
                this._txtNeedMoney.text = "" + Language.getString(70860) + _loc_2.buyValue;
                _loc_3 = 0;
                _loc_4 = Cache.instance.copy.defenseCopy.copyShopBuyItems;
                _loc_6 = 0;
                while (_loc_6 < _loc_4.length)
                {
                    
                    _loc_5 = _loc_4[_loc_6];
                    if (_loc_5.itemCode == _loc_2.itemCode)
                    {
                        _loc_3 = _loc_5.amount;
                        break;
                    }
                    _loc_6++;
                }
                this._item.amount = _loc_2.maxBuyAmount - _loc_3;
                if (this._item.amount <= 0)
                {
                    this._txtName.htmlText = HTMLUtil.addColor(this._item.itemData.name, GlobalStyle.colorHong);
                    this._item.filters = [FilterConst.colorFilter2];
                }
                else
                {
                    this._txtName.htmlText = ItemsUtil.getItemName(this._item.itemData);
                    this._item.filters = [];
                }
            }
            return;
        }// end function

        private function showCursor(event:MouseEvent) : void
        {
            CursorManager.currentCurSorType = CursorManager.BUY;
            CursorManager.showCursor(CursorManager.BUY);
            return;
        }// end function

        private function hidCursor(event:MouseEvent) : void
        {
            CursorManager.currentCurSorType = CursorManager.Arrow;
            CursorManager.showCursor(CursorManager.Arrow);
            return;
        }// end function

        private function onClickHandler(event:MouseEvent) : void
        {
            var _loc_2:Object = {};
            _loc_2.itemCode = this.data.itemCode;
            _loc_2.amount = 1;
            Dispatcher.dispatchEvent(new DataEvent(EventName.DefenseCopyShopBuy, _loc_2));
            return;
        }// end function

    }
}
